package com.tarena.lbs.basic.web.repoistory.impl;

import com.tarena.lbs.basic.web.mapper.UserMapper;
import com.tarena.lbs.basic.web.repoistory.UserRepository;
import com.tarena.lbs.pojo.basic.bo.UserBO;
import com.tarena.lbs.pojo.basic.dos.UserDO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserRepositoryImpl implements UserRepository {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void saveUser(UserBO userBO) {
        //转成do对应数据库
        UserDO userDO=new UserDO();
        BeanUtils.copyProperties(userBO,userDO);
        userMapper.saveUser(userDO);
    }

    @Override
    public UserBO getUserByPhone(String phone) {
        UserDO userDO=userMapper.selectUserByPhone(phone);
        if (userDO!=null){
            UserBO userBO=new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }

    @Override
    public UserBO getUserById(Integer userId) {
        //select * from lbs_user where id=#{userId}
        UserDO userDO=userMapper.selectUserById(userId);
        if (userDO!=null){
            UserBO userBO=new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }

    @Override
    public void updateUserStatus(Integer id, int i) {
        UserDO userDO=new UserDO();
        userDO.setId(id);
        userDO.setStatus(i);
        userMapper.updateUserStatus(userDO);
    }
}
